﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using System.Web;

namespace BartonExtension
{
    public static class StringExtensions
    {
        public static string FormatWith(this string formatStr,params object[] parameters)
        {
            return string.Format(formatStr,parameters);
        }

        public static bool isNullOrEmpty(this string str)
        {
            return string.IsNullOrEmpty(str);
        }

        public static string ToJson(this object obj)
        {
            return JsonConvert.SerializeObject(obj).Replace(@"\", "") ;
        }

        public static T FromJson<T>(this string jsonString)
        {
            if (jsonString.isNullOrEmpty())
                return default(T);
            T TObject = JsonConvert.DeserializeObject<T>(jsonString);
            return TObject;
        }

        public static string DateTimeFileName(this DateTime datetime)
        {
            string str = DateTime.Now.ToString("yyyyMMddhhmmss");
            return str;
        }

        public static string HtmlDecode(this string str)
        {
            return HttpUtility.HtmlDecode(str);
        }
    }
}
